function RegRoomData()
{
    this.reserveSeq = null;
    this.golfClubInfo = null;
    this.openYn = null;
    this.ment = null;
    this.location = null;
    this.reserveDate = null;
    this.bookingTime = null;
    this.password = null;
    this.procStatus = null;
    this.roundingInfo = "D";
    this.holeInfo = null;
    this.invitCnt = null;
    this.sex = null;
    this.age = null;
    this.average = null;
    this.smokeYn = null;
    this.joinYn = null;
    this.regId = null;
    this.bookUserId = null;
    this.modId = null;
    this.rUserName = null;
}

// 
var JoinRoomCreate = function()
{
	thisJoinRoomCreate = this;
    this.TAG = " < JoinRoomCreate > ";
	//Log = document.globalObj;
	tag = "joinRoomCreate";
    this.cm = new ConnectionManager();
    this.mListData = null;
    
	golf_course_form = null;
	hole_info_form = null;
	booking_year_form = null;
	booking_month_form = null;
	booking_day_form = null;
	booking_hour_form = null;
	booking_minute_form = null;
	
	process_status_form = null;
	
	create_password_form = null;
	
	round_info_select_form = null;
	
	loc_info_form = null;
	
	create_age_form = null;
	
	create_average_form = null;
	
	create_rusername_form = null;
	
	create_invitcnt_form = null;
    
    this.regRoomData = new RegRoomData();
    
    this.reserveSeq = null;
    
//    reservation_sid_name = ["RS001", "WR001", "DR001"];
//    reservation_service_name = ["reservSearchList", "WatingreservMainSearchList", "DonationMainReservList"];
//    search_reservation = 0;
//    search_area = 0;
//    search_course = 0;

};

/**
 * 등록데이터 관리 클래스
 */

JoinRoomCreate.prototype = {
    constructor : JoinRoomCreate,
    /**
     * 나의 예약정보 가져오기
     */
    getJoinRoomData : function(reservation, area, step)
    {
    	console.log(this.TAG, "getJoinRoomData()");
    	
       var mJson = new MJson();
        
//        mJson.putDevice(MJson.DEVICE.OID, "0001"); // 기본설정
//        mJson.putDevice(MJson.DEVICE.SCREEN, "100");
//        mJson.putDevice(MJson.DEVICE.DVID, "100");
//        mJson.putDevice(MJson.DEVICE.MODEL, "Iphone4");
//        mJson.putDevice(MJson.DEVICE.FIRMWARE, "ios5");
        
        mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
        mJson.putPub(MJson.PUB.SID, "JR001");
        mJson.putPub(MJson.PUB.SERVICENAME, "getMyReservInfo");
        mJson.putPub(MJson.PUB.LISTCOUNT, "100");
        mJson.putPub(MJson.PUB.CURRPAGENO, "1");

        //alert(mJson.getJsonString());
        
        thisJoinRoomCreate.cm.requestGet(mJson.getJsonString(), function(jsonData) {
        	
        	if(jsonData.msp.contents.items != undefined) {
        	
	        	if(jsonData.msp.contents.items.length != undefined) {
		    		for( var i=0; i<jsonData.msp.contents.items.length; i++) {
		    			
		    			thisJoinRoomCreate.mListData.push(jsonData.msp.contents.items[i]);
		    		}
	        	} else {
	        		thisJoinRoomCreate.mListData.push(jsonData.msp.contents.items);
	        	}
	        	
	        	thisJoinRoomCreate.viewList(jsonData);
        	}
        	
        }, function(e) {
        	
        	alert("error :: " + JSON.stringify(e));
        	
        });
    },
    /**
     * 페이지가 보여질때
     */
    onPageShow : function(event) {
    	
    	thisJoinRoomCreate.mListData = null;
    	thisJoinRoomCreate.mListData = new Array();
    	
    	thisJoinRoomCreate.initForm();
    	
    	thisJoinRoomCreate.initViewData();
    	
        // 초기 부킹 데이터 가져오기
    	thisJoinRoomCreate.getJoinRoomData(null, null, null);

    	//이벤트 초기화
    	thisJoinRoomCreate.initEvent();
    	// 버튼 이벤트 등록
    },
    /**
     * 폼 가져오기
     */
    initForm: function() {
    	console.log(this.TAG + "initForm()");
    	
    	golf_course_form = $("#golf_course");
    	hole_info_form = $("#hole_info");
    	
    	booking_year_form = $("#booking_year");
    	booking_month_form = $("#booking_month");
    	booking_day_form =$("#booking_day");
    	booking_hour_form = $("#booking_hour");
    	booking_minute_form = $("#booking_minute");
    	
    	process_status_form = $('#process_stats_radio');
    	
    	create_password_form = $("#create_password");
    	
    	round_info_select_form = $("#round_info_select");
    	
    	loc_info_form = $("#loc_info");
    	
    	create_age_form = $("#create_age");
    	
    	create_average_form = $("#create_average");
    	
    	create_rusername_form = $("#create_rusername");
    	
    	create_invitcnt_form = $("#create_invitcnt");
    },
    /**
     * 폼 초기 데이터값 세팅
     */
    initViewData: function() {

    	console.log(this.TAG + "initViewData()");
    	
    	for( var i=0; i<60; i++) {
    		booking_minute_form.append("<option value="+utility.replaceString(i)+">"+utility.replaceString(i)+"</option>");
    	}
    	
    	for( var j=0 ; j<31; j++) {
    		booking_day_form.append("<option value="+utility.replaceString(j+1)+">"+utility.replaceString(j+1)+"</option>");
    	}
    	
    	for( var k=0 ; k<12; k++) {
    		booking_month_form.append("<option value="+utility.replaceString(k+1)+">"+utility.replaceString(k+1)+"</option>");
    	}
    	
    	for( var a=0 ; a<24; a++) {
    		booking_hour_form.append("<option value="+utility.replaceString(a+1)+">"+utility.replaceString(a+1)+"</option>");
    	}
    	
    	booking_minute_form.change();
    	booking_day_form.change();
    	booking_month_form.change();
    	booking_hour_form.change();
    		
    },
    viewList: function(jsonData) 
    {
    	var option = new StringBuffer();
    	//var listData = new RoothisJoinRoomCreate.mListData();
    	var selector = $("#round_info_select");

    	//alert(JSON.stringify(thisJoinRoomCreate.mListData));
    	
    	for(var i=0; i<thisJoinRoomCreate.mListData.length; i++)
    	{
    		var golfclubId;
    		if( thisJoinRoomCreate.mListData[i].golfclubId != undefined )
    			golfclubId = thisJoinRoomCreate.mListData[i].golfclubId;
    		
    		var golfClubInfo;
    		if( thisJoinRoomCreate.mListData[i].golfClubInfo != undefined )
    			golfClubInfo = thisJoinRoomCreate.mListData[i].golfClubInfo;
    		
    		var holeInfo;
    		if( thisJoinRoomCreate.mListData[i].holeInfo != undefined )
    			holeInfo = thisJoinRoomCreate.mListData[i].holeInfo;
    		
    		var reserveDate;
    		if( thisJoinRoomCreate.mListData[i].reserveDate != undefined )
    			reserveDate = thisJoinRoomCreate.mListData[i].reserveDate;    		
    		
    		var bookingDay;
    		if( thisJoinRoomCreate.mListData[i].bookingDay != undefined )
    			bookingDay = thisJoinRoomCreate.mListData[i].bookingDay;

    		var bookingTime;
    		if( thisJoinRoomCreate.mListData[i].bookingTime != undefined )
    			bookingTime = thisJoinRoomCreate.mListData[i].bookingTime;
    		
/*    		var option = "<option value=#>" + 
    		golfclubId + " " + 
    		golfClubInfo + "/" + 
    		holeInfo  + "/" +
    		reserveDate + " (" + bookingDay +
    		") /" + bookingTime +"</option>";*/
    		
    		
    		//alert(option);
    		
    		var test_option = "<option value=" + i + ">스카이72 하늘코스 / 18H / 2012.05.31(수) / 07:00</option>"
    			
    		var option = new StringBuffer();
    		option.append("<option value='" + i + "'>");
    		option.append(golfclubId);
    		option.append(" ");
    		option.append(golfClubInfo);
    		option.append(" / ");
    		option.append(holeInfo+"H");
    		option.append(" / ");
    		option.append(reserveDate);
    		option.append("("+bookingDay+")");
    		option.append(" / ");
    		option.append(bookingTime);
    		option.append("</option>");
    	
    		selector.append(option.toString());
    	}
    	//alert("~~~");
    	selector.selectmenu('refresh');
    	
    	//listview.listview("refresh");
    	
    	
    	 //$("#total_listview > li").on("click", this.onClick );
    	 
    	
    },
    refreshForm: function () {
		booking_year_form.change();
		booking_month_form.change();
		booking_day_form.change();
		booking_hour_form.change();
		booking_minute_form.change();
    },
    initEvent: function() {
    	
    	
    	// 수정보안!!
    	$('#hole_info').keydown(function(event){
    		  //alert(event.which);
    		  if (event.which && (event.which  > 47 && event.which  < 58 || event.which == 8)) {
    		    //alert('숫자임!');
    			  console.log(thisJoinRoomCreate.TAG + "number");
    		  } else {
    		    //alert('숫자아님!');
    			  console.log(thisJoinRoomCreate.TAG + "not number");
    	
    		    event.preventDefault();
    		  }
    		});
    	
    	
    	$('#round_info_select').change(function(event) {
    		//alert(thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].reserveDate.split('.').join(":"));
//    		alert($('#round_info_select option:selected').val());
    		//alert(thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].golfClubInfo);
    		
    		if($('#round_info_select option:selected').val() == "-1") { // 직접입력
    			
        		golf_course_form.val("");
        		hole_info_form.val(0);
    			
        		booking_year_form.val("2012");
        		booking_month_form.val("01");
        		booking_day_form.val("01");
        		booking_hour_form.val("01");
        		booking_minute_form.val("00");        		
        		
        		thisJoinRoomCreate.refreshForm();
        		
    			return;
    		}
    		
    		//console.log($('#round_info_select option:selected').val());
    		var golfClubInfo = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].golfClubInfo;
    		
    		
    		//var golfClubInfo = thisJoinRoomCreate.mListData[0].golfClubInfo;
    		
    		//thisJoinRoomCreate.regRoomData.golfClubInfo = golfClubInfo;
    		
    		//console.log(thisJoinRoomCreate.mListData);
    		
    		thisJoinRoomCreate.reserveSeq = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].reserveSeq;
    		
    		var golfclubId = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].golfclubId;

    		var holeInfo = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].holeInfo;
    		
    		var reserveDateArray = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].reserveDate.split(".");
    		
    		var bookingDay = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].bookingDay;

    		var bookingTimeArray = thisJoinRoomCreate.mListData[$('#round_info_select option:selected').val()].bookingTime.split(":");
    		
    		var holeCourse = golfclubId + "/" + golfClubInfo;

    		//golf_course_form.val(holeCourse);
    		golf_course_form.val(holeCourse); // golfclubId는 들어오지 않음..
    		
    		hole_info_form.val(holeInfo);
    		
    		//$('"#booking_month')[3].attr('selected', 'selected');
    		//$('#booking_month option').eq(3).attr('selected', 'selected');
    		
    		//booking_year_form.val(reserveDateArray[0]);
    		booking_year_form.val(reserveDateArray[0]);
    		booking_month_form.val(reserveDateArray[1]);
    		booking_day_form.val(reserveDateArray[2]);
    		booking_hour_form.val(bookingTimeArray[0]);
    		booking_minute_form.val(bookingTimeArray[1]);
    		
    		//alert(bookingTimeArray[0] + " :: " + bookingTimeArray[1]);
    		
/*    		booking_year_form.change();
    		booking_month_form.change();
    		booking_day_form.change();
    		booking_hour_form.change();
    		booking_minute_form.change();*/
    		
    		thisJoinRoomCreate.refreshForm();
    		
    	});
    	
    	$("#btn_reg_room").on("click", function() {

    		console.log("등록 버튼 클릭!!!!!");
    		//thisJoinRoomCreate.regRoomData.procStatus = $event.target.id == "a1" ? "C" : "E";
    		
    		
    		// data class에 값 세팅
    		thisJoinRoomCreate.regRoomData.golfClubInfo = golf_course_form.val();
    		console.log("골프장/코스:"+golf_course_form.val());
    		thisJoinRoomCreate.regRoomData.openYn = $('[name=openyn]:checked').attr("id") == "d1" ? "Y" : $('[name=openyn]:checked').attr("id") == "d2"?"N":null;

    		thisJoinRoomCreate.regRoomData.ment = $("#reg_ment").val();
    		thisJoinRoomCreate.regRoomData.location = loc_info_form.val();
    		
    		
    		var sb = new StringBuffer();
    		sb.append(booking_year_form.val());
    		sb.append(booking_month_form.val());
    		sb.append(booking_day_form.val());
    		thisJoinRoomCreate.regRoomData.reserveDate = sb.toString();
    		
    		sb.clear();
    		sb.append(booking_hour_form.val());
    		//sb.append(":");
    		sb.append(booking_minute_form.val());
    		thisJoinRoomCreate.regRoomData.bookingTime = sb.toString();
    		
    		thisJoinRoomCreate.regRoomData.password = create_password_form.val();
    		thisJoinRoomCreate.regRoomData.procStatus = $('[name=proc_status]:checked').attr("id") == "a1" ? "C" : $('[name=proc_status]:checked').attr("id") == "a2" ? "E":null;
    		
    		/*M:나의예약정보
    		D:직접입력*/
    		thisJoinRoomCreate.regRoomData.roundingInfo = round_info_select_form.val() == "-1" ? "D" : "M";
    		thisJoinRoomCreate.regRoomData.reserveSeq = thisJoinRoomCreate.regRoomData.roundingInfo === "D"? null : thisJoinRoomCreate.mListData[round_info_select_from.val()].reserveSeq;
    		thisJoinRoomCreate.regRoomData.holeInfo = hole_info_form.val();
    		thisJoinRoomCreate.regRoomData.invitCnt = create_invitcnt_form.val();
    		thisJoinRoomCreate.regRoomData.sex = $('[name=sex]:checked').attr("id");
    		thisJoinRoomCreate.regRoomData.age = create_age_form.val();
    		thisJoinRoomCreate.regRoomData.average = create_average_form.val();
    		thisJoinRoomCreate.regRoomData.smokeYn = $('[name=smoke]:checked').attr("id");
    		thisJoinRoomCreate.regRoomData.joinYn = $('#create_joiny_checkbox').is(':checked') ? "Y": "N";
    		thisJoinRoomCreate.regRoomData.regId = document.globalObj.LOGIN_DATA.userId;	// 등록자 아이디 ?
    		thisJoinRoomCreate.regRoomData.bookUserId = document.globalObj.LOGIN_DATA.userId;	// 부킹장 아이디 ?
    		thisJoinRoomCreate.regRoomData.modId = document.globalObj.LOGIN_DATA.userId;	// 수정자 아이디 ?
    		thisJoinRoomCreate.regRoomData.rUserName = create_rusername_form.val();
    		
    	    var dataList = new Array();
    	    dataList.push(thisJoinRoomCreate.regRoomData.reserveSeq);
    	    dataList.push(thisJoinRoomCreate.regRoomData.golfClubInfo);
    	    dataList.push(thisJoinRoomCreate.regRoomData.openYn);
    	    dataList.push(thisJoinRoomCreate.regRoomData.ment);
    	    dataList.push(thisJoinRoomCreate.regRoomData.location);
    	    dataList.push(thisJoinRoomCreate.regRoomData.reserveDate);
    	    dataList.push(thisJoinRoomCreate.regRoomData.password);
    	    dataList.push(thisJoinRoomCreate.regRoomData.bookingTime);
    	    dataList.push(thisJoinRoomCreate.regRoomData.procStatus);
    	    dataList.push(thisJoinRoomCreate.regRoomData.roundingInfo);
    	    dataList.push(thisJoinRoomCreate.regRoomData.holeInfo);
    	    dataList.push(thisJoinRoomCreate.regRoomData.invitCnt);
    	    dataList.push(thisJoinRoomCreate.regRoomData.sex);
    	    dataList.push(thisJoinRoomCreate.regRoomData.age);
    	    dataList.push(thisJoinRoomCreate.regRoomData.average);
    	    dataList.push(thisJoinRoomCreate.regRoomData.smokeYn);
    	    dataList.push(thisJoinRoomCreate.regRoomData.joinYn);
    	    dataList.push(thisJoinRoomCreate.regRoomData.regId);
    	    dataList.push(thisJoinRoomCreate.regRoomData.modId);
    	    dataList.push(thisJoinRoomCreate.regRoomData.bookUserId);
    	    dataList.push(thisJoinRoomCreate.regRoomData.rUserName);
    	    console.log(thisJoinRoomCreate.regRoomData);
    	    
    	    for(var i=0; i<dataList.length; i++)
    	    {
    	    	if(dataList[i] == undefined || dataList[i] == "" ||  dataList[i] == null) 
    	    	{
    	    		if( i == 0 )
    	    		{
    	    			if(dataList[i] == null ) 
    	    			{
    	    				if( thisJoinRoomCreate.regRoomData.roundingInfo === "D") continue;
    	    			}
    	    		}
    	    		
    	    		if(i == 6)
    	    		{
	    	    		if(dataList[i] == undefined || dataList[i] == "") 
	    	    		{
	    	    			if(thisJoinRoomCreate.regRoomData.openYn === "Y") continue;
	    	    		}
    	    		}
    	    		


    	    		alert("모두 입력하셔야 합니다. " + i);
    	    		
    	    		return;
    	    	}
    	    }
    	    
	    	var mJson = new MJson();
	    	
	    	mJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);

	    	mJson.putPub(MJson.PUB.SID, "JR001");
	       mJson.putPub(MJson.PUB.SERVICENAME, "registJoinRoom");
	       mJson.putParameter(MJson.PARAMETER.RESERVESEQ, thisJoinRoomCreate.reserveSeq == null ? "":thisJoinRoomCreate.reserveSeq === undefined ? "":thisJoinRoomCreate.reserveSeq);
	       mJson.putParameter(MJson.PARAMETER.GOLFCLUBINFO, thisJoinRoomCreate.regRoomData.golfClubInfo);
	       mJson.putParameter(MJson.PARAMETER.OPENYN, thisJoinRoomCreate.regRoomData.openYn);
	       mJson.putParameter(MJson.PARAMETER.MENT, thisJoinRoomCreate.regRoomData.ment);
	       mJson.putParameter(MJson.PARAMETER.LOCATION, thisJoinRoomCreate.regRoomData.location);
	       mJson.putParameter(MJson.PARAMETER.RESERVEDATE, thisJoinRoomCreate.regRoomData.reserveDate);
	       mJson.putParameter(MJson.PARAMETER.BOOKINGTIME, thisJoinRoomCreate.regRoomData.bookingTime);
	       mJson.putParameter(MJson.PARAMETER.PASSWORD, thisJoinRoomCreate.regRoomData.password);
	       mJson.putParameter(MJson.PARAMETER.PROCSTATUS, thisJoinRoomCreate.regRoomData.procStatus);
	       mJson.putParameter(MJson.PARAMETER.ROUNDINGINFO, thisJoinRoomCreate.regRoomData.roundingInfo);
	       mJson.putParameter(MJson.PARAMETER.HOLEINFO, thisJoinRoomCreate.regRoomData.holeInfo);
	       mJson.putParameter(MJson.PARAMETER.INVITCNT, thisJoinRoomCreate.regRoomData.invitCnt);
	       mJson.putParameter(MJson.PARAMETER.SEX, thisJoinRoomCreate.regRoomData.sex);
	       mJson.putParameter(MJson.PARAMETER.AGE, thisJoinRoomCreate.regRoomData.age);
	       mJson.putParameter(MJson.PARAMETER.AVERAGE, thisJoinRoomCreate.regRoomData.average);
	       mJson.putParameter(MJson.PARAMETER.SMOKEYN, thisJoinRoomCreate.regRoomData.smokeYn);
	       mJson.putParameter(MJson.PARAMETER.JOINYN, thisJoinRoomCreate.regRoomData.joinYn);
	       mJson.putParameter(MJson.PARAMETER.REGID, thisJoinRoomCreate.regRoomData.regId);
	       mJson.putParameter(MJson.PARAMETER.BOOKUSERID, thisJoinRoomCreate.regRoomData.bookUserId); // ??
	       mJson.putParameter(MJson.PARAMETER.MODID, thisJoinRoomCreate.regRoomData.modId); // ??
	       mJson.putParameter(MJson.PARAMETER.RUSERNAME, thisJoinRoomCreate.regRoomData.rUserName);
	       //return;
	       thisJoinRoomCreate.cm.requestGet(mJson.getJsonString(), function(jsonData) {
	    	   
	        	console.log(mJson.getJsonString());
	        	console.log(JSON.stringify(jsonData));
	    	   
	    	   if(jsonData.msp.result.code === "00000")
	    		   $.mobile.changePage("join_room_my.html");
	        }, function(e) {
	        	alert("error :: " + JSON.stringify(e));
	        });
	       
    	} );
    }
};

